package com.sunwayworld.basemodule.common.eptstorage.acqconfig.resource.impl;

import com.sunwayworld.basemodule.common.eptstorage.acqconfig.bean.LimsEquiptAcqConfigInstBean;
import com.sunwayworld.basemodule.common.eptstorage.acqconfig.resource.LimsEquiptAcqConfigResource;
import com.sunwayworld.basemodule.common.eptstorage.acqconfig.service.LimsEquiptAcqConfigService;
import com.sunwayworld.cloud.module.equipt.acqconfig.resource.impl.CoreEquiptAcqConfigResourceImpl;
import com.sunwayworld.framework.data.page.Page;
import com.sunwayworld.framework.log.annotation.Log;
import com.sunwayworld.framework.log.annotation.LogType;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@GikamBean
public class LimsEquiptAcqConfigResourceImpl extends CoreEquiptAcqConfigResourceImpl implements LimsEquiptAcqConfigResource {

    @Autowired
    private LimsEquiptAcqConfigService limsEquiptAcqConfigService;

    @Override
    public LimsEquiptAcqConfigService getService() {
        return limsEquiptAcqConfigService;
    }

    @Override
    @Log(value = "发送消息", type = LogType.CONTROLLER)
    @PostMapping("/{id}/send")
    public void sendMessage(@PathVariable String id, @RequestBody(required = false) String message) {
        getService().sendMessage(id);
    }

    @Override
    @Log(value = "新增设备指令", type = LogType.INSERT)
    @PostMapping("/{id}/instructions")
    public Long insertLimsAcqConfigInst(@PathVariable String id, RestJsonWrapperBean wrapperBean) {
        return getService().insertLimsAcqConfigInst(id, wrapperBean);
    }

    @Override
    @Log(value = "查询设备指令", type = LogType.SELECT)
    @PostMapping("/{id}/instructions/queries")
    public Page<LimsEquiptAcqConfigInstBean> selectLimsAcqConfigInstPaginationByDcuConfigId(@PathVariable String id, RestJsonWrapperBean wrapperBean) {
        return getService().selectLimsAcqConfigInstPaginationByDcuConfigId(id, wrapperBean);
    }

    @Override
    @Log(value = "删除指令", type = LogType.DELETE)
    @DeleteMapping("/{id}/instructions")
    public void deleteLimsAcqConfigInst(@PathVariable String id, RestJsonWrapperBean wrapperBean) {
        getService().deleteLimsAcqConfigInst(id, wrapperBean);
    }

    @Override
    @Log(value = "测试发送", type = LogType.SELECT)
    @PostMapping("/{id}/action/test-send")
    public void testSend(@PathVariable String id, RestJsonWrapperBean wrapperBean) {
        getService().testSend(id, wrapperBean);
    }

    @Override
    @Log(value = "测试发送", type = LogType.SELECT)
    @GetMapping("/instructions/queries/selectable")
    public List<LimsEquiptAcqConfigInstBean> selectInstructionSelectableList() {
        return getService().selectInstructionSelectableList();
    }

    @Override
    @Log(value = "测试关闭连接", type = LogType.SELECT)
    @RequestMapping(
            value = {"/{eptId}/action/closeConnect"},
            method = {RequestMethod.PUT}
    )
    public String closeConnect(String eptId, RestJsonWrapperBean wrapper) {
        return getService().closeConnect(eptId);
    }

    @Override
    @Log(value = "请求设备温度湿度", type = LogType.SELECT)
    @RequestMapping(
            value = {"/request/tempAndHum/{id}"},
            method = {RequestMethod.POST}
    )
    public String requestEquiptTempAndHum(@PathVariable String id, RestJsonWrapperBean wrapper) {
        return getService().requestEquiptTempAndHum(id);
    }
}
